package com.hrt.manage.role.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hrt.bean.Role;
import com.hrt.manage.role.dao.RoleDao;
import com.hrt.manage.role.service.RoleService;

@Service
public class RoleServiceImpl implements RoleService {

	@Autowired
	private RoleDao dao;

	@Override
	public List<Role> queryByPage(int pageIndex, int pageSize) {
		// TODO Auto-generated method stub
		List<Role> list=new ArrayList<Role>();
		list =dao. queryByPage( pageIndex,  pageSize);
		
		return list;
	}

	@Override
	public Long totalCount() {
		// TODO Auto-generated method stub
		 return dao.totalCount();
	}

	@Override
	public Long totalCount(Map condition) {
		// TODO Auto-generated method stub
		return  dao.totalCount(condition);
	}

	@Override
	public List<Role> queryByPage(List<Map<String, Object>> conditions,
			Integer pageIndex, Integer pageSize) {
		// TODO Auto-generated method stub
		List<Role> results=new ArrayList<Role>();
		results=dao.queryByPage(pageIndex, pageSize);
		return results;
	}

	@Override
	@Transactional
	public Long[] deleteById(Long[] idArr) {
		// TODO Auto-generated method stub
				List<Long> delArr=new ArrayList<Long>();
				if(idArr!=null && idArr.length>0){
					for(Long id:idArr){
					Role c=dao.getById(id);
					c.setIsdelete(new Integer(1));
					dao.updateEntity(c);
					delArr.add(id);
					}
				}
				return (Long[]) delArr.toArray();
	}

	@Override
	public String queryRoleByPinYin(String pinyin) {
		// TODO Auto-generated method stub
		return dao.queryRoleByPinYin( pinyin);
	}

	@Override
	public Timestamp getDate() {
		// TODO Auto-generated method stub
		return dao.getDate();
	}

	@Override
	@Transactional
	public Long saveRole(Role role) {
		// TODO Auto-generated method stub
		return dao.saveEntity(role);
	}

	@Override
	public Role getRoleById(Long roleId) {
		// TODO Auto-generated method stub
		return dao.getRoleByid(roleId);
	}

	@Override
	@Transactional
	public void updateRole(Role role) {
		// TODO Auto-generated method stub
		dao.updateEntity(role);
	}

	@Override
	public List<Role> listRole() {
		// TODO Auto-generated method stub
		List<Role> results=new ArrayList<Role>();
		results=dao.listRole() ;
		return results;
	}

	@Override
	public List<Role> queryRoleWithOutUsers(Long userId) {
		List<Role> results=new ArrayList<Role>();
		results=dao. queryRoleWithOutUsers(userId);
		return results;
	}

	@Override
	public List<Role> getRoleByIds(Long[] ids) {
		// TODO Auto-generated method stub
		List<Role> results=new ArrayList<Role>();
		results=dao.getRoleByid(ids);
		return results;
	}





}
